﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using emp.BLL;

/// <summary>
///PubFun 的摘要说明
/// </summary>
public class PubFun
{
	public  PubFun()
	{
		
	}
    public static string regionRole = ConfigurationSettings.AppSettings["regionRole"];
    public static string marketRole = ConfigurationSettings.AppSettings["marketRole"];
    public static string publicRole = ConfigurationSettings.AppSettings["publicRole"];
  public enum RandomType
    {
        时间=1,
        数值=2,
        Guid=3,
        bit3=4
    }

    /// <summary>
    /// 生成随机码
    /// </summary>
    /// <param name="prefix">前缀</param>
    /// <param name="rtype">类型</param>
    /// <returns></returns>
    public static string GenerateRandom(string prefix, RandomType rtype)
    {
        string result = string.Empty;
        switch (rtype)
        {
            case  RandomType.时间:
                result = prefix + DateTime.Now.ToFileTime();
                break;
            case  RandomType.数值:
                result = prefix + NextInt64(new Random());
                break;
            case RandomType.Guid:
                result = prefix + System.Guid.NewGuid().ToString().Replace("-", string.Empty);
                break;
            case RandomType.bit3:
                while (true)
                {
                    string bitresult = Bit3(prefix);
                    if (!new Campaign().Exists(bitresult))
                    {
                        return bitresult;
                    }
                }
               

        }
        return result;
    }

    private static string Bit3(string prefix)
    {
        string result = string.Empty;
        for (int i = 0; i < 5; i++)
        {         
            Random rand = new Random(Guid.NewGuid().GetHashCode());
            result += rand.Next(0, 9);

        }
        return prefix + result;
    }

    public static Int64 NextInt64(Random rnd)
    {
        var buffer = new byte[sizeof(Int64)];
        rnd.NextBytes(buffer);
        return BitConverter.ToInt64(buffer, 0);
    }

    /// <summary>
    /// 活动状态
    /// </summary>
    public enum CAM_STATUS
    {
        新建=0,
        报批=1,
        区域经理审批未通过=10,
        区域经理审批通过=11,
        市场部审批未通过=20,
        市场部审批通过 = 21
    }

    

    public static void Show(System.Web.UI.Page page, string msg)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript'>alert(\"" + msg.ToString() + "\");</script>");
    }

    public static void Show(System.Web.UI.Page page, string msg, string redirectpage)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript'>alert(\"" + msg.ToString() + "\");location.replace('" + redirectpage + "');</script>");
    }




}